package com.newcapec.servlet;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Description:显示登录界面的servlet类
 * @Author:yangshupeng
 * @Date: 2022/3/21 22:04
 * @Version:1.0
 */
@WebServlet(value = "/login.html",name = "ShowLoginHtmlServlet",loadOnStartup = 1)
public class ShowLoginHtmlServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求和响应的内容的编码格式
        /*req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");*/

        String type = req.getParameter("type");
        String msg = "";
        if (type != null) {
            switch (type) {
                case "1":
                    msg = "用户名不存在！！！";
                    break;
                case "2":
                    msg = "密码错误！！！";
                    break;
                case "3":
                    msg = "没有权限访问该页面，请登录后进行访问！！！";
                    break;
                case "4":
                    msg = "恭喜您，注册成功！请重新登录！";
                    break;
                case "5":
                    msg = "验证码错误，请重新输入";
            }
        }
        //讲servlet中的数据传递给jsp页面
        req.setAttribute("msg",msg);
        //请求转发
        req.getRequestDispatcher("WEB-INF/jsp/login.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
